﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PictrueSimpleSyndication
{
    public class SingleCase
    {
        private SingleCase() { }

        private static SingleCase _SingleCase = new SingleCase();

        public static SingleCase GetInstance() { return _SingleCase; }

        private Dictionary<Type, object> _Type2Instance = new Dictionary<Type, object>();

        /// <summary>
        /// 获取注册的实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetRegister<T>()
        {
            if (_Type2Instance.ContainsKey(typeof(T)))
                return (T)_Type2Instance[typeof(T)];

            return default(T);
        }

        /// <summary>
        /// 注册实例
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        public void Register<T>(T t)
        {
            _Type2Instance[typeof(T)] = t;
        }
    }
}
